<template>
	<om-page :title="pageTitle" class="om-font-size">
		<view class="margin-top-xs">
			<view class="content">
				<uni-list>
					<uni-list-item v-for="item in groupList" @click="selectGroup(item)">
						<view>{{ item.groupName }}</view>
					</uni-list-item>
				</uni-list>
			</view>
		</view>
	</om-page>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: '选择分组',
				applyId: '',
				groupList: [],
			};
		},
		methods: {
			selectGroup(item){
				let _that = this;
				uni.showModal({
					title: '确认移动',
					content: '该应用将从原分组转移到你选定的“'+item.groupName+'”分组',
					showCancel: true,
					success(res){
						if(res.confirm){
							_that.om.request('wxNewGroupMenu/addAppsToGroup', {
								groupId: item.id,
								appIds: _that.applyId
							},'post').then(res => {
								if (res.succeed) {
									uni.navigateBack()
								}else{
									_that.om.toast(res.msg);
								}
							});
						}
					}
				})
			},
			getGroupList(){
				let _that = this;
				_that.om.request('wxNewGroupMenu/getGroupList',{
					appId: _that.applyId
				}).then(res => {
					if (res.succeed) {
						_that.groupList = res.value;
					}
				});
			}
		},
		onLoad(e) {
			this.applyId = e.applyId
			this.getGroupList()
		},
	};
</script>

<style lang="scss" scoped>
	.content {
		.row{
			display: flex;
			flex-direction: row;
			align-items: center;
			.icon{
				width: 30px;
				height: 30px;
				border-radius: 6px;
				margin-right: 13px;
			}
			.text{
				font-size: 13px;
			}
		}
	}
</style>
